package com.csun.cmny.provider.web.frontend;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.OpcFlowMessageGroupWay;
import com.csun.cmny.provider.model.vo.message.MessageWayVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OpcFlowMessageGroupWayService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-11-11 21:13
 * @Description:
 */
@RestController
@RequestMapping(value = "/flowMessageGroupWay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OpcFlowMessageGroupWayController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private OpcFlowMessageGroupWayService opcFlowMessageGroupWayService;

    /**
     * 绑定推送方式
     */
    @PostMapping(value = "/bind")
    public Wrapper bind(@RequestBody OpcFlowMessageGroupWay opcFlowMessageGroupWay) {

        Integer result = opcFlowMessageGroupWayService.bind(opcFlowMessageGroupWay);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

        //return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), result);
    }

    /**
     * 解绑推送方式
     */
    @PostMapping(value = "/untied")
    public Wrapper untied(@RequestBody OpcFlowMessageGroupWay opcFlowMessageGroupWay) {

        Integer result = opcFlowMessageGroupWayService.untied(opcFlowMessageGroupWay);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

        //return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), result);
    }

    /**
     * 查询推送方式 -- 根据Id
     */
    @PostMapping(value = "/queryWayList")
    public Wrapper queryWayList(@RequestBody OpcFlowMessageGroupWay opcFlowMessageGroupWay) {

        List<MessageWayVo> list = opcFlowMessageGroupWayService.queryWayList(opcFlowMessageGroupWay);

        //return WrapMapper.ok(list);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), list);
    }

}
